package com.meals.system.api.system;

import com.meals.system.api.system.vo.IndexInfoVO;
import com.meals.system.api.system.vo.WhitesMealIndexCarouselVO;
import com.meals.system.api.system.vo.WhitesMealIndexConfigGoodsVO;
import com.meals.system.common.Constants;
import com.meals.system.common.IndexConfigTypeEnum;
import com.meals.system.service.WhitesMealCarouselService;
import com.meals.system.service.WhitesMealIndexConfigService;
import com.meals.system.util.Result;
import com.meals.system.util.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.tomcat.util.bcel.Const;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Description:
 * Parm:
 * return:
 * Author: Chen
 * Date: 2021/12/4
 */
@RestController
@Api(value = "v1", tags = "0-1.白餐系统首页接口")
@RequestMapping("/user-api/v1")
public class WhitesMealSystemIndexAPI {

    @Resource
    private WhitesMealCarouselService whitesMealCarouselService;

    @Resource
    private WhitesMealIndexConfigService whitesMealIndexConfigService;

    @GetMapping("/index-infos")
    @ApiOperation(value = "获取首页数据", notes = "轮播图、新品、推荐等")
    public Result<IndexInfoVO> indexInfo(){
        IndexInfoVO indexInfoVO = new IndexInfoVO();
        List<WhitesMealIndexCarouselVO> carousels = whitesMealCarouselService.getCarouselsForIndex(Constants.INDEX_CAROUSEL_NUMBER);
        List<WhitesMealIndexConfigGoodsVO> hotGoodses = whitesMealIndexConfigService.getConfigGoodsesForIndex(IndexConfigTypeEnum.INDEX_GOODS_HOT.getType(), Constants.INDEX_GOODS_HOT_NUMBER);
        List<WhitesMealIndexConfigGoodsVO> newGoodses = whitesMealIndexConfigService.getConfigGoodsesForIndex(IndexConfigTypeEnum.INDEX_GOODS_NEW.getType(), Constants.INDEX_GOODS_NEW_NUMBER);
        List<WhitesMealIndexConfigGoodsVO> recommendGoods = whitesMealIndexConfigService.getConfigGoodsesForIndex(IndexConfigTypeEnum.INDEX_GOODS_RECOMMOND.getType(), Constants.INDEX_GOODS_RECOMMOND_NUMBER);
        indexInfoVO.setCarousels(carousels);
        indexInfoVO.setHotGoodses(hotGoodses);
        indexInfoVO.setNewGoodses(newGoodses);
        indexInfoVO.setRecommendGoodses(recommendGoods);
        return ResultGenerator.genSuccessResult(indexInfoVO);

    }
}
